local blaze = require "blaze"
local app = require "app"
local game = require "club.threecard.jacksorbetter"

local M = game.ui.element()

local log = blaze.logging.get("BetViser")

local function update(self, state)
    self.bet_value_txt.text = app.i18n.number(state.amount, "chip3")
    self.bet_max_tip:SetActive(state.is_max)
end

M.store_watchers = {
    bet_amounts = {
        ["$"] = function(self, store, state)
            update(self, state)
        end,

        ["初始化下注档位"] = function(self, store, state, args)
            update(self, state)
        end,

        ["最大注"] = function(self, store, state, args)
            update(self, state)
        end,

        ["改变下注"] = function(self, store, state, args)
            update(self, state)
        end,
    }
}

function M:ctor()
    self.res = "club.threecard.jacksorbetter/ui/ingame.b:bet_operator"
end

function M:on_injected(bind)
    bind("button.click", self.btn_add, self.add_ivk)
    bind("button.click", self.btn_sub, self.sub_ivk)
end

function M:add_ivk()
    app.store.bet_amounts.up()
end

function M:sub_ivk()
    app.store.bet_amounts.down()
end

return M